package main

import (
	"fmt"
	"os"
)

func main() {
	f := createFile("/tmp/defer.txt")
	defer closeFile(f)
	writeFile(f)
}

func createFile(p string) *os.File {
	fmt.Println("createing ..")
	file, e := os.Create(p)
	if e != nil {
		panic(e)
	}
	return file
}

func writeFile(f *os.File) {
	fmt.Println("writing .. ")
	fmt.Fprintln(f, "data..")
}

func closeFile(f *os.File) {
	fmt.Println("closing..")
	f.Close()

}
